package com.wsd.smartcarwasher.service;

import com.wsd.smartcarwasher.dao.CardRecordMapper;
import com.wsd.smartcarwasher.domain.CardRecord;
import com.wsd.smartcarwasher.domain.CardRecordExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class CardRecordService {
    private static final Logger logger = LoggerFactory.getLogger(CardRecordService.class);

    @Resource
    private CardRecordMapper cardRecordDao;

    int update(CardRecord cardRecord){

        cardRecord.setRefundTime(new Date());
        return this.cardRecordDao.updateByPrimaryKey(cardRecord);
    }


    public CardRecord getCardRecordInfo(String ucId){

        CardRecordExample cardRecordExample=new CardRecordExample();
        cardRecordExample.createCriteria().andUcIdEqualTo(ucId);
        List<CardRecord> cardRecords=this.cardRecordDao.selectByExample(cardRecordExample);
        CardRecord cardRecord=new CardRecord();
        for (CardRecord c:cardRecords
             ) {
            cardRecord.setCreateTime(c.getCreateTime());
            cardRecord.setFirstTimes(c.getFirstTimes());
            cardRecord.setUserId(c.getUserId());
            cardRecord.setPayTimes(c.getPayTimes());
            cardRecord.setCardId(c.getCardId());
            cardRecord.setRefundTime(c.getRefundTime());
        }
        return cardRecord ;
    }


}
